﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2013/4/10 星期三 22:06:07
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Sector7.Framework.Enums;

namespace Sector7.Framework.Core
{
    /// <summary>
    /// 警告提示类
    /// </summary>
    public sealed class Alert
    {
        #region Public functions
        /// <summary>
        /// 显示警告窗口
        /// </summary>
        /// <param name="alertType">警告类型</param>
        /// <param name="message">信息</param>
        /// <returns>操作结果</returns>
        public static MessageBoxResult ShowDialog(AlertType alertType, string message)
        {
            Alert alert = new Alert();
            alert.Initialize(alertType);

            return alert.ShowDialog(message);
        }

        /// <summary>
        /// 显示警告窗口
        /// </summary>
        /// <param name="alertType">警告类型</param>
        /// <param name="format">信息格式化字符串</param>
        /// <param name="args">要设置格式的对象数组</param>
        /// <returns>操作结果</returns>
        public static MessageBoxResult ShowDialog(AlertType alertType, string format, params object[] args)
        {
            return ShowDialog(alertType, string.Format(format, args));
        }
        #endregion

        #region Private functions
        /// <summary>
        /// 私有构造方法
        /// </summary>
        private Alert(){}

        /// <summary>
        /// 初始化变量
        /// </summary>
        /// <param name="alertType">告警类型</param>
        private void Initialize(AlertType alertType)
        {
            switch (alertType)
            {
                case AlertType.Notification:
                    m_button = MessageBoxButton.OK;
                    m_icon = MessageBoxImage.Information;
                    m_caption = "提示";
                    break;
                case AlertType.Warning:
                    m_button = MessageBoxButton.OK;
                    m_icon = MessageBoxImage.Warning;
                    m_caption = "警告";
                    break;
                case AlertType.Question:
                    m_button = MessageBoxButton.YesNo;
                    m_icon = MessageBoxImage.Question;
                    m_caption = "确认";
                    break;
                case AlertType.Error:
                    m_button = MessageBoxButton.OK;
                    m_icon = MessageBoxImage.Error;
                    m_caption = "错误";
                    break;
                case AlertType.None:
                default:
                    m_button = MessageBoxButton.OK;
                    m_icon = MessageBoxImage.None;
                    m_caption = string.Empty;
                    break;
            }
        }

        /// <summary>
        /// 显示告警提示框
        /// </summary>
        /// <param name="message">告警信息内容</param>
        /// <returns></returns>
        private MessageBoxResult ShowDialog(string message)
        {
            return MessageBox.Show(message, m_caption, m_button, m_icon);
        }
        #endregion

        #region Members
        /// <summary>
        /// 告警框按钮
        /// </summary>
        private MessageBoxButton m_button = MessageBoxButton.OK;

        /// <summary>
        /// 告警框图标
        /// </summary>
        private MessageBoxImage m_icon = MessageBoxImage.None;

        /// <summary>
        /// 告警框标题
        /// </summary>
        private string m_caption = "提示";
        #endregion
    }
}
